'use strict';
import React from 'react';
import {Button, DatePicker, Form, Input, notification, Popconfirm, Table} from 'antd';

import {FormField, FormLayout, ModalFooter, ModalView} from 'antd-extra';
import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';

import ViewTitle from "../../../components/ViewTitle";
import styles from "../../index.less";
import ModalCreateOrEdit2 from "../../dic/modal/ModalCreateOrEdit2";
import UploadPic from "../../../components/UploadPic";

moment.locale('zh-cn');

@Form.create()
@connect(({
            tenant,
            global,
            dynamicLabel,
            dic
          }) => ({...tenant, ...dic, ...dynamicLabel, ...global}))
export default class ModalCreateOrEditSelf extends FormBase {
  constructor(props) {
    super(props);
    const {record} = this.props;
    this.state = {...record};

  }

  renderFoot = () => {
    const {foot, value, callback, modalRef, record, form} = this.props;

    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            form.validateFields((err, values) => {
              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              values.code=record?record.code:"ESP"+moment().format('YYYYMMDDHHmmss');
              callback(values);
              modalRef.close();
            });

          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };

  render() {
    const {record = {}, form} = this.props;
    const {date, experimentRequire, conclusion,experimentDesc,target,experimentMan,memo,experimentName} = record;
    const _date = date ? moment(date) : moment();
    return <div>
      <FormLayout form={form} cols={1}>
        <FormField
          label={'实验日期'}
          name={'date'}
          required={true}
          initialValue={_date}
        >
          <DatePicker style={{width: "100%"}}></DatePicker>
        </FormField>
        <FormField
          label={'实验名称'}
          name={'experimentName'}
          required={true}
          initialValue={experimentName}
        >
          <Input style={{width: "100%"}}></Input>
        </FormField>
        <FormField
          label={'实验目的和课题'}
          name={'target'}
          required={true}
          initialValue={target}
        >
          <Input.TextArea style={{width: "100%"}}></Input.TextArea>
        </FormField>
        <FormField
          label={'实验人'}
          name={'experimentMan'}
          required={true}
          initialValue={experimentMan}
        >
          <Input style={{width: "100%"}}></Input>
        </FormField>
        <FormField
          label={'实验要求或标准'}
          name={'experimentRequire'}
          required={true}
          initialValue={experimentRequire}
        >
          <Input.TextArea style={{width: "100%"}}></Input.TextArea>
        </FormField>
        <FormField
          label={'实验过程描述'}
          name={'experimentDesc'}
          required={true}
          initialValue={experimentDesc}
        >
          <Input.TextArea style={{width: "100%"}}></Input.TextArea>
        </FormField>
        <FormField
          label={'结论内容'}
          name={'conclusion'}
          required={true}
          initialValue={conclusion}
        >
          <Input.TextArea style={{width: "150%"}}></Input.TextArea>
        </FormField>
        <FormField
          label={'备注'}
          name={'memo'}
          required={true}
          initialValue={memo}
        >
          <Input.TextArea style={{width: "150%"}}></Input.TextArea>
        </FormField>
      </FormLayout>
      {this.renderFoot()}
    </div>;
  }
}
